#!/usr/bin/env python3.3

#
#  Filename: e59.py
#  Author  : lukas singer
#
#  Comment : Created by createSolution.sh
#

#import euler
#from euler import *

def pe59():
  l=[]
  #read the file
  with open('cipher1.txt','r') as f:
    l=[int(s) for s in f.read().split(',')]
  
  #generate passwords
  for c1 in range(ord('a'),ord('z')+1):
    for c2 in range(ord('a'),ord('z')+1):
      for c3 in range(ord('a'),ord('z')+1):
        #password posibilities: pw=c1+c2+c3

        #decrypt the list
        s=''
        j=0
        #its faster to check j than to check i%3
        for i in range(0,len(l)):
          if j==0: 
            s+=chr(l[i]^c1)
          if j==1: 
            s+=chr(l[i]^c2)
          if j==2: 
            s+=chr(l[i]^c3)
            j=-1
          j+=1

        #look for common word
        c=0
        if ' the ' in s: c+=1
        if ' is '  in s: c+=1
        if ' was ' in s: c+=1
        if ' and ' in s: c+=1
        if c>=3:
          #print(s,'\n\n')
          #print(chr(c1)+chr(c2)+chr(c3)+'\n')
          print(sum(ord(a) for a in s))
          exit()

if __name__=="__main__":
  pe59()

